﻿
<div class="page-content-wrap">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline tool-btn">
                <button class="layui-btn layui-btn-small layui-btn-danger del_Btn hidden-xs" data-id="tab" data-url="/Home/DeleteCom"><i class="layui-icon">&#xe640;</i></button>
            </div>
            <div class="layui-inline">
                <input type="text" id="title" required lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
            </div>
            <button id="search" class="layui-btn layui-btn-normal" onclick="return false" lay-submit="search">搜索</button>
        </div>
    </form>
    <div id="table-list" class="layui-form" style="height: 400px;">
        <input type="hidden" id="index" />
        <table id="tab"></table>
    </div>
</div>
@section script{
    <script>
        $("#tab").datagrid({
            idField: 'id',
            singleSelect: false,
            rownumbers: true,
            pagePosition: 'bottom',
            pagination: true,//分页
            pageSize: 10,//每页显示条数
            pageList: [10, 15, 20, 30, 50, 100], //调整每页显示条数
            fit: true,//宽高跟随父面板
            fitColumns: true,//水平滚动条
            nowrap: false,//折行显示
            columns: [[
                { field: 'check', checkbox: true, width: 100, align: 'center' },
                { field: 'id', title: '评论编号', width: 180, align: 'center' },
                { field: 'title', title: '文章标题', width: 180, align: 'center' },
                { field: 'content', title: '评论内容', width: 180, align: 'center' },
                { field: 'commDate', title: '评论时间', width: 180, align: 'center' },
                { field: 'uname', title: '用户名', width: 180, align: 'center' },
            ]],
            url: '/Home/CommentTable',
        })
        layui.use(['jquery', 'layer', 'dialog', 'checkbox'], function () {
            var $ = layui.jquery;
        });
        $('.del_Btn').click(function () {
			    var id = "#" + $(this).attr("data-id");
			    var $table = $(id).datagrid('getChecked');
			    var no = new Array();
			    for (var i = 0; i < $table.length; i++) {
			        if (i == 0) {
			            no = "no=" + $table[i].id;
			        } else {
			            no += "&no=" + $table[i].id;
			        }
			    }
			    var url = $(this).attr('data-url');
			    layer.confirm('您确定要删除选中项?', function (index) {
			        //do something
			        $.get(url, no, function (data) {
			            layer.msg(data);
			            location.reload();
			        })
			        layer.close(index);
			    });
			    return false;
        });
        $("#search").click(function(){
				$("#tab").datagrid({
					queryParams: {
						name: $("#title").val()
					}
				});
			})
    </script>
}

